package com.yx.cloud.utils;

import android.content.Context;

import com.yx.cloud.bean.tmall.AuthorizedLogin;
import com.yx.cloud.bean.tmall.TmallUnbindDeviceParam;
import com.yx.cloud.product.laser.inxni.INXNIConstant;
import com.yx.cloud.product.sdk.tmall.AliGenieSdk;

public class AliHttpRequest_Runnable implements Runnable {
    private String tag;
    private Object mObject;
    private Context mContext;

    public void initialization(String a, Object object) {
        tag = a;
        mObject = object;
        ThreadUtils.getInstance().createThread(this);
    }

    public void initialization(String a, Object object, Context context) {
        tag = a;
        mObject = object;
        mContext = context;
        ThreadUtils.getInstance().createThread(this);
    }

    @Override
    public void run() {
        if ("getAuthCode".equals(tag)) {
            //获取authcode
            AliGenieSdk.getAuthCode();
        } else if ("detectAccessToken".equals(tag)) {
//            AliGenieSdk.detectAccessToken();
        } else if ("auth_login".equals(tag)) {
            //授权登录
            AuthorizedLogin alogin = (AuthorizedLogin) this.mObject;
            AliGenieSdk.get().authorizedLogin(alogin);
        } else if ("verification_code".equals(tag)) {
            //手机授权登录获取验证码
            AuthorizedLogin alogin = (AuthorizedLogin) this.mObject;
            AliGenieSdk.userPhoneNumberAuthorizedLoginVerificationCode(alogin);
        } else if ("auth_login_user_list".equals(tag)) {
            //获取已授权登录的用户列表
            AuthorizedLogin alogin = (AuthorizedLogin) this.mObject;
            AliGenieSdk.getAuthorizedLoginsList(alogin);
        } else if ("phoneNumber_login".equals(tag)) {
            //直接 通过手机号生成精灵账号进行登录
            String sessionId = (String) this.mObject;
            AliGenieSdk.phoneNumberAuthorizedLogin(sessionId);
        } else if ("authentication".equals(tag)) {
            //鉴权
            AuthorizedLogin alogin = (AuthorizedLogin) this.mObject;
            AliGenieSdk.accessTokenAuthentication(alogin);
        } else if ("getDevice_id".equals(tag)) {
            //根据mac获取设备id
            String mac = (String) this.mObject;
            AliGenieSdk.getDeviceId(mac);
        } else if ("getRobot_Information".equals(tag)) {
            //天猫配网成功后，获取扫地机信息进行配网
            try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String drvice_id = (String) this.mObject;
            AliGenieSdk.getRobotInformation(drvice_id);
        } else if ("device_info".equals(tag)) {
            //设备信息（是否在线）
            String device_id = (String) this.mObject;
            AliGenieSdk.getDeviceStatusInfo(device_id);
        } else if ("unbind_device".equals(tag)) {
            //解绑设备
            TmallUnbindDeviceParam param = (TmallUnbindDeviceParam) this.mObject;
            AliGenieSdk.unbindDevice(param);
        } else if ("getUserDevice_list".equals(tag)) {
            //获取用户设备列表
            AliGenieSdk.getUserBindDeviceList();
        } else if ("taobao_account_login".equals(tag)) {
            //通过已有的天猫账号进行登录
            String userIdentifier = (String) this.mObject;
            AliGenieSdk.taoBaoAuthLogin(INXNIConstant.SESSION_ID, userIdentifier);
        } else if ("genie_acciunt_login".equals(tag)) {
            //通过精灵账号登录
            String userIdentifier = (String) this.mObject;
            AliGenieSdk.tmallGenieTypeLogin(INXNIConstant.SESSION_ID, userIdentifier);
        } else if ("unbind_user".equals(tag)) {
            //解绑用户
            AliGenieSdk.unbindUser();
        } else if ("aligenie_user_info".equals(tag)) {
            //获取三方绑定的精灵账号信息
            AuthorizedLogin alogin = (AuthorizedLogin) this.mObject;
            AliGenieSdk.getAligenieUserInfo(alogin);
        } else if ("getDevice_basic_info".equals(tag)) {
            //获取基站固件信息
            String deviceOpenId = (String) this.mObject;
            AliGenieSdk.getDeviceBasicInfo(deviceOpenId);
        }
    }
}
